package ru.usu.gv.gui;

import ru.usu.gv.core.GraphEngine;
import ru.usu.gv.core.I18nService;
import ru.usu.gv.gui.layout.CircularLayout;
import ru.usu.gv.gui.layout.ILayout;
import ru.usu.gv.gui.layout.RandomLayout;
import ru.usu.gv.gui.layout.SimpleGridLayout;
import ru.usu.gv.gui.layout.SpringMultiScaleLayout;
import ru.usu.gv.gui.layout.StandardSpringLayout;
import ru.usu.gv.gui.layout.dynamic.DynamicFDNetworkLayout;
import ru.usu.gv.gui.layout.dynamic.DynamicMDSNetworkLayout;
import ru.usu.gv.gui.layout.dynamic.TestVNCNetworkLayout;
import ru.usu.gv.gui.layout.fd.StandardForceDirectedLayout;
import ru.usu.gv.gui.layout.hierarchy.HierarchyClusterLayout;
import ru.usu.gv.gui.layout.mds.CitiesLayout;
import ru.usu.gv.gui.layout.mds.ClassicalScalingLayout;
import ru.usu.gv.gui.layout.mds.DistanceScalingLayout;
import ru.usu.gv.gui.layout.mds.DistanceScalingLayout2;
import ru.usu.gv.gui.layout.mds.DistanceScalingLayout4;
import ru.usu.gv.gui.layout.mds.LandmarkClassicalLayout;
import ru.usu.gv.gui.layout.mds.MDSLayout;
import ru.usu.gv.gui.layout.mds.RoadsLayout;
import ru.usu.gv.gui.layout.rw.CommuteTimeLayout;
import ru.usu.gv.gui.layout.rw.CopyOfCommuteTimeLayout;
import ru.usu.gv.gui.layout.rw.CosineCommuteTimeLayout;
import ru.usu.gv.gui.layout.rw.DiffusionLayout;
import ru.usu.gv.gui.layout.rw.FastCommuteTime;
import ru.usu.gv.gui.layout.rw.KatzLayout;
import ru.usu.gv.gui.layout.rw.RWRLayout;
import ru.usu.gv.gui.layout.rw.SqrtCommuteTimeLayout;
import ru.usu.gv.gui.layout.spectral.DegreeEigenProjection;
import ru.usu.gv.gui.layout.spectral.EigenProjection;

import javax.swing.AbstractAction;
import javax.swing.Action;

import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;

/**
 * @author spupyrev
 * 03.11.2008
 */
public class GVLayoutActions
{
	public List<Action> getLayoutActions()
	{
		List<Action> result = new ArrayList<Action>();
		//Simple
		result.add(buildLayoutAction(I18nService.get("layout.random"), RandomLayout.getInstance()));
		result.add(buildLayoutAction(I18nService.get("layout.grid"), SimpleGridLayout.getInstance()));
		result.add(buildLayoutAction(I18nService.get("layout.circular"), CircularLayout.getInstance()));
		result.add(null);
		//Force-directed
		result.add(buildLayoutAction(I18nService.get("layout.force_directed"), StandardForceDirectedLayout.getInstance()));
		result.add(buildLayoutAction(I18nService.get("layout.spring"), StandardSpringLayout.getInstance()));
		result.add(buildLayoutAction(I18nService.get("layout.multilevel"), SpringMultiScaleLayout.getInstance()));
		result.add(buildLayoutAction(I18nService.get("layout.modularity"), HierarchyClusterLayout.getInstance()));
		result.add(buildLayoutAction(I18nService.get("layout.sndm"), DynamicFDNetworkLayout.getInstance()));
		result.add(buildLayoutAction(I18nService.get("layout.sndm2"), DynamicMDSNetworkLayout.getInstance()));
		result.add(buildLayoutAction("test_vnc", TestVNCNetworkLayout.getInstance()));
		result.add(null);

		return result;
	}

	public List<Action> getMDSLayoutActions()
	{
		List<Action> result = new ArrayList<Action>();
		result.add(buildLayoutAction(I18nService.get("layout.mds.classical"), ClassicalScalingLayout.getInstance()));
		result.add(buildLayoutAction(I18nService.get("layout.mds.landmark"), LandmarkClassicalLayout.getInstance()));
		result.add(buildLayoutAction(I18nService.get("layout.mds.distance"), DistanceScalingLayout.getInstance()));
		result.add(buildLayoutAction("Test disconnected2", DistanceScalingLayout2.getInstance()));
		result.add(buildLayoutAction("Test lin-log", DistanceScalingLayout4.getInstance()));
		result.add(buildLayoutAction("Test cities", CitiesLayout.getInstance()));
		result.add(buildLayoutAction("Test roads", RoadsLayout.getInstance()));
		result.add(buildLayoutAction(I18nService.get("layout.mds.mds"), MDSLayout.getInstance()));

		return result;
	}

	public List<Action> getSpectralLayoutActions()
	{
		List<Action> result = new ArrayList<Action>();
		result.add(buildLayoutAction("Eigen projection", EigenProjection.getInstance()));
		result.add(buildLayoutAction("Degree-normilized eigen projection", DegreeEigenProjection.getInstance()));

		return result;
	}

	public List<Action> getRandomWalkLayoutActions()
	{
		List<Action> result = new ArrayList<Action>();
		result.add(buildLayoutAction("Commute time", CommuteTimeLayout.getInstance()));
		result.add(buildLayoutAction("Commute timeRW", CopyOfCommuteTimeLayout.getInstance()));
		result.add(buildLayoutAction("Sqrt commute time", SqrtCommuteTimeLayout.getInstance()));
		result.add(buildLayoutAction("Fast sqrt commute time", FastCommuteTime.getInstance()));
		result.add(buildLayoutAction("Cosine commute time", CosineCommuteTimeLayout.getInstance()));
		result.add(buildLayoutAction("Katz", KatzLayout.getInstance()));
		result.add(buildLayoutAction("Diffusion", DiffusionLayout.getInstance()));
		result.add(buildLayoutAction("Random walk with restart", RWRLayout.getInstance()));

		return result;
	}

	private Action buildLayoutAction(String title, final ILayout layout)
	{
		return new AbstractAction(title)
		{
			public void actionPerformed(ActionEvent e)
			{
				GraphEngine.getInstance().startLayout(layout);
			}
		};
	}
}
